package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.domain.Packsack;
import cn.wolfcode.trip.base.domain.Product;
import cn.wolfcode.trip.base.mapper.ProductMapper;
import cn.wolfcode.trip.base.query.PacksackQueryObject;
import cn.wolfcode.trip.base.service.IPacksackService;
import cn.wolfcode.trip.base.service.IProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 登录相关的控制器
 */
@Controller
@RequestMapping("/packsack")
public class PacksackController {
    @Autowired
    private IPacksackService packsackService;
    @Autowired
    private ProductMapper productMapper;
    @GetMapping
    @ResponseBody
    public Object list(PacksackQueryObject qo) {
        qo.setOrderBy("gaintime desc");
        PageInfo query = packsackService.query(qo);
        return query;
    }
    @PostMapping("/sign")
    @ResponseBody
    public Object save(Packsack packsack) {
        //去数据库中找签到的礼品
        Product product = productMapper.selectByPrimaryKey(Product.SIGN_PRODUCT);
        packsack.setProduct(product);
        packsackService.saveSign(packsack);
        return "111";
    }
}
